<template>
  <div class="meeting-file">
    <div
      v-for="(item,index) in previewFile"
      :key="`file-${index}`"
      class="meeting-file-item"
    >
      <span
        class="name"
        @click="downloadFile(item.filePreviewAddress)"
      > {{item.fileName}}</span>
      <i
        @click="downloadFile(item.filePath)"
        class="el-icon-download icon"
      ></i>
    </div>
  </div>
</template>

<script>
import { imUserUploadPreview } from '@/api/conferences'
export default {
  name: 'MeetingFile',
  data () {
    return {
      previewFile: []
    }
  },
  created () {
    this.conferenceId = this.$route.query.conferenceId
  },
  mounted () {
    // 获取文件
    this.handleImUserUploadPreview()
  },
  methods: {
    // 下载文件
    downloadFile (path) {
      window.open(path)
    },
    // 查看会议相关文件
    async handleImUserUploadPreview () {
      try {
        const { data } = await imUserUploadPreview(this.conferenceId)
        this.previewFile = data
        this.relativeFileVisi = this.previewFile.length === 0
      } catch {
        this.relativeFileVisi = true
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.meeting-file {
  .meeting-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 12px;
    border-bottom: 1px solid #eee;
    .name {
      cursor: pointer;
    }
    .icon {
      cursor: pointer;
    }
  }
}
</style>
